home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / comm / bbs / FilePather13.lha / FilePather / Docs / Text_Encapsulation.txt < prev    next >
Encoding:
Text File  |  1995-04-07  |  18.3 KB  |  482 lines

  1. @Start_of_text
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                           -= USERS STANDARDS GROUP =-
  10.  
  11.  
  12.  
  13.  
  14.                           Text Encapsulation Standard
  15.  
  16.                             Version 1.31, Release 1
  17.                                  Updated 4.4.95
  18.  
  19.                                  (TES-130.TXT)
  20.  
  21.  
  22.  
  23.                              Public Release Version
  24.                                 LATIN-1 document
  25.  
  26.  
  27.  
  28.  
  29.                                   Endorsed by
  30.                              USERS STANDARDS GROUP
  31.  
  32.                            Written by Peter Bornhall
  33.  
  34.  
  35.  
  36.  
  37.  
  38.                           Copyright 1995, Johan Torin
  39.                               All rights reserved
  40.  
  41.  
  42.  
  43.     ========================================================================
  44.      INDEX                                                              0.0
  45.     ========================================================================
  46.  
  47.     0.1  SECTION LIST
  48.  
  49.         Index ...................................................... 0.0
  50.             Section list ........................................... 0.1
  51.  
  52.         Preface .................................................... 1.0
  53.             Distribution ........................................... 1.1
  54.             Disclaimer ............................................. 1.2
  55.  
  56.         Introduction ............................................... 2.0
  57.             Background ............................................. 2.1
  58.             Purpose ................................................ 2.2
  59.  
  60.         Using the standard ......................................... 3.0
  61.             The problem ............................................ 3.1
  62.             The solution ........................................... 3.2
  63.             Loopholes .............................................. 3.3
  64.  
  65.         Developers ................................................. 4.0
  66.             Keystrings ............................................. 4.1
  67.             Handling ............................................... 4.2
  68.             Pseude code ............................................ 4.3
  69.  
  70.         History .................................................... 5.0
  71.  
  72.         Author ..................................................... 6.0
  73.  
  74.  
  75.  
  76.     ========================================================================
  77.      PREFACE                                                            1.0
  78.     ========================================================================
  79.  
  80.     1.1  DISTRIBUTION
  81.  
  82.      This  document is freeware, and may be spread on any medium without the
  83.     author's permission.  You are in fact encouraged to spread this document
  84.     to  your  friends  and  your local Bulletin Board Systems.  However, the
  85.     document is copyrighted, and may NOT be changed in any way.
  86.  
  87.      The document may NOT be sold in any way, nor included in any commercial
  88.     packages without the written permission from the author.
  89.  
  90.  
  91.     1.2  DISCLAIMER
  92.  
  93.      The author of this document will NOT be held responsible for ANY damage
  94.     caused  by  persons  or  software  using this standard.  The author also
  95.     reserves the right to change the standard as he sees fit.
  96.  
  97.  
  98.  
  99.     ========================================================================
  100.      INTRODUCTION                                                       2.0
  101.     ========================================================================
  102.  
  103.     2.1  BACKGROUND
  104.  
  105.      This standard was developed by Johan Torin during December 1994. A  pre
  106.     release was released, but it wasn't spread very much, and there  were no
  107.     software support for it at the time. Johan also worked on his FilePather
  108.     standard and software, which was intended  to offer support for the Text
  109.     Encapsulation Standard (TES for short).
  110.  
  111.      Since  awaiting  a full release of the FilePather software, the TES got
  112.     put  "on  hold" for a while.  Some minor changes took place, and this is
  113.     the  final  release-version  of the specifications.  The actual standard
  114.     hasn't changed very much, though.
  115.  
  116.  
  117.     2.2  PURPOSE
  118.  
  119.      The  Text Encapsulation Standard provides an easy way to be able to get
  120.     rid  of  annoying BBS advertisements added to text files.  There are two
  121.     categories of BBS ads;
  122.  
  123.         1. Ads placed inside file archives
  124.         2. Ads placed at the beginning and at the end of a textfile
  125.  
  126.      This standard is aiming to "cure" the second category, the textfiles.
  127.  
  128.  
  129.  
  130.     ========================================================================
  131.      USING THE STANDARD                                                 3.0
  132.     ========================================================================
  133.  
  134.     3.1  THE PROBLEM
  135.  
  136.      Ads  in  textfiles.   Very annoying things.  You would probably like to
  137.     get rid of them as much as I do, so let's take a look at this example of
  138.     what might happen to a textfile.
  139.  
  140.      Lets say that the textfile looks like this before upload;
  141.  
  142.         --- 8< -------------------------------------------
  143.         This is an example text to demonstrate the
  144.         use of the Text Encapsulation Standard.
  145.         --- 8< -------------------------------------------
  146.  
  147.      Then,  the  textfile  gets uploaded to a BBS, which puts ads in it.  So
  148.     the resulting file might look something like this;
  149.  
  150.         --- 8< -------------------------------------------
  151.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  152.         > Call this excellent board now!  123-4567 890 <
  153.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  154.         This is an example text to demonstrate the
  155.         use of the Text Encapsulation Standard.
  156.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  157.         > Cool sysop, fast warezzz, good ratios, call! <
  158.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  159.         --- 8< -------------------------------------------
  160.  
  161.      The   file  just  tripled  its  size.   Not  unusual,  I've  personally
  162.     downloaded  a  file which was some 10kB in the file listing, but I ended
  163.     up  with  nearly  40kB!   And that was added by ONE single BBS!  If this
  164.     keeps  repeating,  the  file  will soon contain more ads than real text!
  165.     And THAT is what we want to prevent!
  166.  
  167.      The  solution is pretty easy, or so it may seem.  Simply remove the ads
  168.     from  the textfile.  Yes, but doing it by hand is very time-consuming to
  169.     say  the  least, and automated strippers aren't 100% reliable, no matter
  170.     what the author says.  A stripper may have very sophisticated algorithms
  171.     to  sense  what  should  be  stripped, but it will probably end up doing
  172.     something wrong sooner rather than later.  That's the fact of life.
  173.  
  174.  
  175.     3.2  THE SOLUTION
  176.  
  177.      By  placing  keystrings  on  the  first and last lines of the textfile,
  178.     either  when writing it or when added by an automatic upload checker, it
  179.     will  be  possible  to locate the REAL text in the file.  The keystrings
  180.     are  "@Start_of_text" and "@End_of_text".  The @ char was chosen because
  181.     it's  used by other standards supporting textfiles, like for example the
  182.     FilePather (FILEPATH.LST), FILE_ID.DIZ and the File Description Standard
  183.     (FILEDESC.TXT).   This makes it fast and easy to implement into existing
  184.     tools.
  185.  
  186.      Ok, now for an example of how to use it;
  187.  
  188.         --- 8< -------------------------------------------
  189.         @Start_of_text
  190.         This is an example text to demonstrate the
  191.         use of the Text Encapsulation Standard.
  192.         @End_of_text
  193.         --- 8< -------------------------------------------
  194.  
  195.      After uploading, it might look like this;
  196.  
  197.         --- 8< -------------------------------------------
  198.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  199.         > Call this excellent board now!  123-4567 890 <
  200.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  201.         @Start_of_text
  202.         This is an example text to demonstrate the
  203.         use of the Text Encapsulation Standard.
  204.         @End_of_text
  205.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  206.         > Cool sysop, fast warezzz, good ratios, call! <
  207.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  208.         --- 8< -------------------------------------------
  209.  
  210.      Later,  when  this textfile is uploaded to a BBS that supports the Text
  211.     Encapsulation  Standard,  it will be stripped from the ads, and the file
  212.     will return to its original state;
  213.  
  214.         --- 8< -------------------------------------------
  215.         @Start_of_text
  216.         This is an example text to demonstrate the
  217.         use of the Text Encapsulation Standard.
  218.         @End_of_text
  219.         --- 8< -------------------------------------------
  220.  
  221.      Easy as that, really.
  222.  
  223.  
  224.     3.3  LOOPHOLES
  225.  
  226.      "But what about textfiles that doesn't contain these keystrings?"
  227.  
  228.      Sure,  that  IS a problem, but it might still prevent the textfile from
  229.     GROWING in size.  If there are no keystrings in the textfile, the upload
  230.     checker  should  add  them anyway, encapsulating the textfile.  Some ads
  231.     might  actually  be encapsulated together with the real text, but in the
  232.     long  run,  at  least the file won't get any bigger.  And a smaller file
  233.     will cost YOU less time and money to transfer, as well as taking up less
  234.     space on your harddrive.
  235.  
  236.  
  237.     ========================================================================
  238.      DEVELOPERS                                                         4.0
  239.     ========================================================================
  240.  
  241.     4.1  KEYSTRINGS
  242.  
  243.      Unlike  the keystrings for FilePather, FILE_ID.DIZ and File Description
  244.     Standard,  softwares supporting this standard should be prepared to find
  245.     keystrings  consisting  of  upper and lowercased characters mixed in any
  246.     way.    This  means  that  "@StArT_Of_tExT"  for  example,  is  a  legal
  247.     keystring.
  248.  
  249.      But,  softwares that ADD the keystrings should use the standard strings
  250.     "@Start_of_text" and "@End_of_text".  The same rule applies for software
  251.     that  rewrites the textfile.  So if the software reads "@STaRT_oF_TeXT",
  252.     it should still output "@Start_of_text" if possible.
  253.  
  254.      There is one more thing to consider.  As you might know, some platforms
  255.     use  CR+LF  as a newline character, while most modern platforms use only
  256.     LF.   You  will  have  to  take this into account in your software.  For
  257.     example, an upload checker should examine the textfile to see if it's in
  258.     CR+LF  format or LF-only, and write the keystring + newline according to
  259.     what is used in the file.  The same applies when reading the keystrings,
  260.     you should be aware that there might be CR+LF or LF alone.
  261.  
  262.         Text file with LF       ->  Write keystring + LF
  263.         Text file with CR+LF    ->  Write keystring + CR + LF
  264.  
  265.         CR = ASCII 13, Carriage Return
  266.         LF = ASCII 10, Line Feed
  267.  
  268.  
  269.     4.2  HANDLING
  270.  
  271.      As  a  developer,  you should be prepared to deal with the most strange
  272.     things,  so  here  are some hints and rules on how to handle some of the
  273.     "common" weird things.
  274.  
  275.      First of all, the @Start_of_text and @End_of_text strings should be the
  276.     first thing on the line, and the only thing.  This means that you should
  277.     always  look  for  @Start_of_text  and  @End_of_text  directly  after  a
  278.     [CR]+LF-sequence or at the very beginning of a file (first byte is "@").
  279.     There must not be anything between the "..._text" string and the newline
  280.     character(s).  Strict rules applies, as you understand.
  281.  
  282.      The second thing to pay attention to is when there are multiple strings
  283.     in the same textfile.  For example;
  284.  
  285.         --- 8< -------------------------------------------
  286.         @Start_of_text
  287.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  288.         > Call this excellent board now!  123-4567 890 <
  289.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  290.         @Start_of_text
  291.         This is an example text to demonstrate the
  292.         use of the Text Encapsulation Standard.
  293.         @End_of_text
  294.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  295.         > Cool sysop, fast warezzz, good ratios, call! <
  296.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  297.         @End_of_text
  298.         --- 8< -------------------------------------------
  299.  
  300.      As you probably have understood by now, the BBS ads are unwanted, which
  301.     means that we want the (in this case) innermost @Sot-@Eot sequence.  The
  302.     thing  to  do,  is  to  always  use  the  FIRST VALID sequence.  A valid
  303.     sequence is considered to be a sequence of;
  304.  
  305.         @Start_of_text
  306.  
  307.         < anything except @Start_of_text >
  308.  
  309.         @End_of_text
  310.  
  311.      Here is a bit of pseudo-code you could take a look at (it may need some
  312.     tweaking to work, though);
  313.  
  314.             do
  315.                 read LINE
  316.                 if LINE = "@Start_of_text" then
  317.                     SOT = 1
  318.                     SOP = seek() - len(LINE)
  319.                 elseif LINE = "@End_of_text" then
  320.                     if SOT = 1 then
  321.                         EOT = 1
  322.                         EOP = seek() - len(LINE)
  323.                     endif
  324.                 endif
  325.             loop until eof() or (SOT = 1 and EOT = 1)
  326.  
  327.      As  you  understand,  it is not 100% percent safe, as this example will
  328.     show;
  329.  
  330.         --- 8< -------------------------------------------
  331.         @Start_of_text
  332.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  333.         > Call this excellent board now!  123-4567 890 <
  334.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  335.         @End_of_text
  336.         @Start_of_text
  337.         This is an example text to demonstrate the
  338.         use of the Text Encapsulation Standard.
  339.         @End_of_text
  340.         @Start_of_text
  341.         /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  342.         > Cool sysop, fast warezzz, good ratios, call! <
  343.         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  344.         @End_of_text
  345.         --- 8< -------------------------------------------
  346.  
  347.      The  routine would pick the first valid sequence, which in this case is
  348.     the  BBS ad itself!  Now, this is probably not likely to happen, because
  349.     even  if  the sysop wants to advertise, he wouldn't do this, as it would
  350.     kill  the  actual  textfile.  And a BBS without users...  No, that's not
  351.     very probable.
  352.  
  353.      One more thing to consider.  If a non-encapsulated textfile contains;
  354.  
  355.         --- 8< -------------------------------------------
  356.         This is example text 1, demonstrating the
  357.         use of the Text Encapsulation Standard.
  358.         @Start_of_text
  359.         This is example text 2, demonstrating the
  360.         use of the Text Encapsulation Standard.
  361.         --- 8< -------------------------------------------
  362.  
  363.      ...then  you  are allowed to strip everything before the @Start_of_text
  364.     marker.   Same  thing  with  the @End_of_text marker, except you have to
  365.     strip  everything  after  the  marker  instead.   If  you  have a better
  366.     solution,  go ahead and use it.  But don't expect others to do the same.
  367.     You may of course let us know, and maybe we'll put it in in the future.
  368.  
  369.  
  370.     4.3  PSEUDE CODE
  371.  
  372.      Since  you  will  have  to take other standards into consideration, for
  373.     example  the  FilePather, FILE_ID.DIZ and the File Description Standard,
  374.     you  should take a look at the supplied pseudo code, which might help in
  375.     the  development of software that supports this standard.  Johan is also
  376.     the  author  of  the  FilePather software, which works according to this
  377.     method.  Ok, here goes;
  378.  
  379.      ***************************
  380.      * Logic of the textcopier *
  381.      ***************************
  382.      * All 'Write's are to an assumed file.
  383.  
  384.      * First you must search after all the different '@'-nodes: S&EOT,
  385.      * Filedesc, FileIdDiz, FilePather, and save start and end pointers.
  386.      * Some pointers has to be adjusted. It will turn out as you test your
  387.      * code. Don't forget to include LF's and eventual CR's in the node.
  388.  
  389.      Write "@Start_of_text",Linefeed
  390.      Write BeginFiledesc -> EndFiledesc ;First write all nodes to the file.
  391.      Write BeginFilepath -> EndFilepath
  392.      Write BeginFileId -> EndFileId
  393.      Write ...              ;Add more if needed.
  394.  
  395.      CurrentStart = StartText ;'@Start_of_text' or start of textfile
  396.      CurrentEnd = EndText    ;'@End_of_text' or end of textfile.
  397.  
  398.      * This code loops until all text that is NOT inside a node is copied.
  399.      Check:
  400.  
  401.      If BeginFileDesc < CurrentEnd Then
  402.          If BeginFileDesc > CurrentStart Then
  403.              CurrentEnd = BeginFileDesc
  404.              NextStart = EndFileDesc
  405.          Endif
  406.      Endif
  407.  
  408.      If BeginFilePath < CurrentEnd Then
  409.          If BeginFilePath > CurrentStart Then
  410.              CurrentEnd = BeginFilePath
  411.              NextStart = EndFilePath
  412.          Endif
  413.      Endif
  414.  
  415.      If BeginFileId < CurrentEnd Then
  416.          If BeginFileId > CurrentStart Then
  417.              CurrentEnd = BeginFileId
  418.              NextStart = EndFileId
  419.          Endif
  420.      Endif
  421.  
  422.      If ...                 ;Add more if needed.
  423.  
  424.      Write CurrentStart -> CurrentEnd
  425.      If CurrentEnd = EndText Then Goto Finito
  426.      CurrentEnd = EndText
  427.      CurrentStart = NextStart
  428.      Goto Check
  429.  
  430.      * If "@End_of_text" wasn't found earlier, then print it now.
  431.      Finito:
  432.      If EndofTextFound = 0
  433.          Write "@End_of_text",Linefeed
  434.      Endif
  435.  
  436.      * Final result: all nodes are moved to just under @SOT, original text
  437.      * is placed directly under.
  438.      ***********************************
  439.  
  440.  
  441.  
  442.     ========================================================================
  443.      HISTORY                                                            5.0
  444.     ========================================================================
  445.  
  446.         1.0     19.12.94  JT   Wrote it.
  447.  
  448.         1.1     20.12.94  JT   Added pseudo code example.
  449.  
  450.         1.1a    21.12.94  JT   Fixed bug in the pseudo code. :)
  451.  
  452.         1.1b      2.1.95  JT   Added info about case insensitivity.
  453.  
  454.         1.1c     12.2.95  JT   Slightly edited.
  455.  
  456.         1.20     24.3.95  PB   Rewritten by Peter Bornhall.
  457.  
  458.         1.30      3.4.95  PB   Added hints for developers.
  459.  
  460.         1.31      4.4.95  JT   Removed some obsolete information.
  461.  
  462.  
  463.     ========================================================================
  464.      AUTHOR                                                             6.0
  465.     ========================================================================
  466.  
  467.      Johan Torin may be contacted via;
  468.  
  469.         FidoNet:    2:203/804.13
  470.          USGNet:    8:100/102.7
  471.           email:    JTorin@Academy.Bastad.se       or
  472.           email:    jt@p13.f804.n203.z2.fidonet.org
  473.  
  474.           Snail:    Johan Torin
  475.                     Fotstad
  476.                     S-31303 Ă…LED
  477.                     SWEDEN
  478.  
  479.  
  480.  
  481. @End_of_text
  482.